Page({

  data: {
  },

  onLoad: function (options) {

 
    var goodData = JSON.parse(options.goodData);

    this.setData({
      goodData: goodData
    })

    console.log(this.data.goodData);
    
  },
  //点击编辑跳转至商品编辑页

alter:function(e){
  
  var goodData = JSON.stringify(e.currentTarget.dataset.gooddata);
  wx.navigateTo({
    url: '../alter-goods/alter-goods?goodData=' + goodData
  
  })
},


//删除该商品
delete:function(e){
  var that = this;
  var app = getApp();
  wx.showModal({
    title: '删除',
    content: '确定删除该商品？',
    cancelText: "否",
    confirmText: "是",
    confirmColor: "red",
    success: function (res) {
      if(res.cancel) {
        wx.showToast({
          title: '取消删除',
        })
      }else {
        wx.request({
          url: "http://47.106.145.141:8080/api/v1/goods",
          method: "DELETE",
          data: {
            "token": app.globalData.key,
            "goodsId": that.data.goodData.id
          },
          header: {
            "content-type": "application/x-www-form-urlencoded"
          },
          success: function (result) {
            console.log(result.data);
            var pages = getCurrentPages();
            var goodpage = pages[pages.length - 2];

            goodpage.setData({
              Refresh: true,
            })
            console.log(goodpage.data.Refresh);
            wx.navigateBack({
              delta: 1
            })
          }
        })
      }
    }
  })
  
}
 
})